﻿using GoodsDALs;
using Goodsmoels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MIShop.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class GoodsController : ControllerBase
    {
        //依赖注入
        private readonly Goodsdal _goodsdal;
        public GoodsController(Goodsdal goodsdal)
        {
            _goodsdal = goodsdal;
        }


        //登录
        [HttpGet]
        public IActionResult Denglu(string UsersName, string UsersPwd)
        {
            if (_goodsdal.DenggLu(UsersName, UsersPwd) != null)
            {
                return Ok(_goodsdal.DenggLu(UsersName,UsersPwd));
            }
            else
            {
                return Ok(-1);

            }
        }


        //注册
        [HttpPost]
        public IActionResult UsersAdd(Users u)
        {
            return Ok(_goodsdal.UsersAdd(u));
        }



        //商品显示
        [HttpGet]
        public IActionResult GoodsShow()
        {
            return Ok(_goodsdal.GoodsShow());
        }

        //  购物车添加
        [HttpPost]
        public IActionResult AddShop(Shops s)
        {
            return Ok(_goodsdal.AddShop(s));

        }

        //购物车显示
        [HttpGet]
        public IActionResult ShopShow()
        {
            return Ok(_goodsdal.ShopShow());

        }

        //商品详情
        [HttpGet]
        public IActionResult GoodsFan(int GoodsId)
        {
            return Ok(_goodsdal.GoodsFan(GoodsId));
        }

        //地址添加
        [HttpPost]
        public IActionResult AddAddr(Addresss a)
        {
            return Ok(_goodsdal.AddAddr(a));
        }

        //地址显示
        [HttpGet]
        public IActionResult AddreShow()
        {
            return Ok(_goodsdal.AddreShow());
        }

        //联动
        [HttpGet]
        public IActionResult CityBing(int Pid)
        {
            return Ok(_goodsdal.CityBing(Pid));
        }


        //删除购物车
        [HttpGet]
        public IActionResult ShopDel(int ShopsId)
        {
            return Ok(_goodsdal.ShopDel(ShopsId));

        }

        //购物车修改
        [HttpPost]
        public IActionResult UpdateShop(int ShopsId, int ShopNum)
        {
            return Ok(_goodsdal.UpdateShop(ShopsId, ShopNum));
        }

        //删除地址
        [HttpGet]
        public IActionResult DelAddre(int AddresId)
        {
            return Ok(_goodsdal.DelAddre(AddresId));
        }

        //编辑地址
        [HttpGet]
        public IActionResult AddreFan(int AddresId)
        {
            return Ok(_goodsdal.AddreFan(AddresId));
        }

        //修改地址
        [HttpPost]
        public IActionResult UpdateAddre(Addresss a)
        {
            return Ok(_goodsdal.UpdateAddre(a));
        }

    }
        
}
